/*
 * @Author: szx
 * @Date: 2022-01-28 13:48:45
 * @LastEditTime: 2022-01-28 14:20:19
 * @Description:
 * @FilePath: \leetcode\700-799\739\739.js
 */
/**
 * @param {number[]} temperatures
 * @return {number[]}
 */
 var dailyTemperatures = function (temperatures) {
    const n = temperatures.length;
    const res = new Array(n).fill(0);
    const st = [0];
    //单调栈
    for (let i = 1; i < n; i++) {
        let top = st[st.length - 1];
        if (temperatures[i] <= temperatures[top]) {
            st.push(i);
        } else {
            while (st.length && temperatures[i] > temperatures[st[st.length - 1]]) {
                top = st.pop();
                res[top] = i - top;
            }
            st.push(i);
        }
    }
    return res;
};
